package com.jay.lang.ref.clazz;

import java.lang.ref.Reference;
import java.lang.ref.SoftReference;

//软引用所指向的对象会根据内存使用情况来决定是否回收，这里内存还充足，所以不会被回收

public class SoftReferenceCls {
	// -Xmx2m -Xms2m
	public static void main(String[] args) {
//		Bean b = new Bean("name", 10);
//		SoftReference<Bean> bean = new SoftReference<Bean>(b);
		SoftReference<Bean> bean = new SoftReference<Bean>(new Bean("name", 10));
		System.gc();
		System.runFinalization();
		System.out.println(bean.get());

		Reference<Bean>[] referent = new SoftReference[100000];
		for (int i = 0; i < referent.length; i++) {
			referent[i] = new SoftReference<Bean>(new Bean("mybean:" + i, 100));
		}

		System.out.println(referent[100].get());

	}
}
